package io.dy.mq;

import io.dy.utils.ThreadUtils;

/**
 * @author dmj
 * @date 2024年03月25日 下午2:00
 */
public class Main {

    public static void main(String[] args) {
        MessageQueue<Integer, String> messageQueue = new MessageQueue<>(3);

        for (int i = 1; i < 11; i++) {
            int id = i;
            new Thread(()->{
                messageQueue.put(new Message<>(id,"消息体-" + id));
            },"生产者线程" + id).start();
        }


        new Thread(()->{
            while (true){
                ThreadUtils.sleepSecond(1);
                Message<Integer, String> take = messageQueue.take();

                messageQueue.take();
            }
        },"消费者线程").start();
    }
}
